import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import org.apache.http.client.methods.HttpPost;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import athome.api.GoodApi;
import athome.api.Http;
import athome.api.OiApi;
import athome.api.ShopApi;
import athome.api.UserApi;
import athome.api.WalkerApi;
import athome.bean.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
 * 4月3日任务
 * 让客户端搜不到没有商品的卖家
 * 让逻辑更严谨
 * @author zzc
 *
 */
public class Demo {
	public static void print(Object s) {
		System.out.println(s);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 // 这是walkerapi的测试代码
		 WalkerApi walker = new WalkerApi();
		walker.setOid(2);
		walker.setGetParams();
		walker.echoGet();
		walker.get();
		WalkerBean walkerBean = walker.getWalker();
		print(walkerBean.getWloc() + "\t" + walkerBean.getWname());
		*/
		/*
		  // 这是userapi的测试代码
		 UserApi user = new UserApi();
		UserBean userBean = new UserBean();
		userBean.setUloc("南区046022").setUname("lyy2").setUpassword("12345").setUphone("12424324");
		print(user.reg(userBean));
		print(user.login(userBean));
		print(user.logout(userBean));*/
		/*OiApi oi = new OiApi();
		oi.setMethod(OiApi.GETORDERS_METHOD);
		oi.setUid(1);
		oi.setState(OiApi.UN_FINISH_STATE);
		oi.setGetParams();
		oi.echoGet();
		oi.get();
		ArrayList<OrderInfo>ois = oi.getOrders();
		if(ois != null) {
			for(OrderInfo oi1 : ois) {
				print(oi1.getOid()+"\t" + oi1.getOtotal() + "\t" + oi1.getUid() + "\t" +oi1.getState());
				ArrayList<OrderGoods>ogs = oi1.getGoodlist();
				for(OrderGoods og : ogs) {
					print(og.getGid() + "\t"+og.getGname() + "\t"+og.getOgtotal());
				}
				print("");
			}
		}
		else {
			print("no data");
		}
		ArrayList<OrderGoods>ogs = new ArrayList<>();
		OrderGoods og = new OrderGoods();
		og.setGid(1).setOgnum(2).setOgtotal(6f);
		ogs.add(og);
		og = new OrderGoods();
		og.setGid(2).setOgnum(1).setOgtotal(12f);
		ogs.add(og);
		OrderInfo oInfo = new OrderInfo();
		oInfo.setGoodlist(ogs);
		oInfo.setOtotal(18f).setOgettime("12:30").setUid(1).setSid(1);
		oi.setMethod(oi.TAKEORDER_METHOD);
		oi.echoGet();
		if(oi.takeOrder(oInfo)) {
			print("sucess");
		}
		else {
			print("failed");
		}*/
	/*	GoodApi api = new GoodApi();
		api.setMethod(api.GETGOOD_METHOD);
		print(api.setGid(2));
		api.setGetParams();
		print(api.isready);
		api.get();
		GoodBean gBean = api.getGood();
		print(gBean.getGid());
		print(gBean.getGprice());
		print(gBean.getGphonepic());
		print(gBean.getGname());
		print("---------------");
		api.setMethod(api.GETGOODS_METHOD);
		api.setSid(12);
		api.setGetParams();
		api.echoGet();
		print(api.isready);
		api.get();
		HashMap<String, ArrayList<GoodBean>> goods = api.getGoods();
		if(goods != null) {
			Set<String>keySet = goods.keySet();
			Iterator<String>iterator = keySet.iterator();
			while(iterator.hasNext()) {
				String key = iterator.next();
				ArrayList<GoodBean>goodlist = goods.get(key);
				print(key);
				for(GoodBean good : goodlist) {
					print(good.getGid());
				}
			}
		}
		else {
			print("no data");
		}*/
		ShopApi api = new ShopApi();
		api.setMethod(api.GETSHOPS_METHOD);
		api.setGetParams();
		api.echoGet();
		print(api.get());
		 //这是商店的测试代码
		/*ShopApi api = new ShopApi();
		api.setMethod(ShopApi.GETSHOP_METHOD);
		api.setSid(1);
		api.setGetParams();
		System.out.println(api.isready);
		api.echoGet();
		api.get();
		ShopBean shopBean = api.getShop();
		System.out.println(api.result() + "\n" + shopBean.getSdesc());
		api.setMethod(ShopApi.GETSHOPS_METHOD);
		api.setLimit(9);
		api.setOffset(1);
		api.setSortType(api.NEW_SORT_TYPE);
		api.setGetParams();
		api.echoGet();
		api.get();
		print(api.result());
		ArrayList<ShopBean>shops = api.getShops();
		for(ShopBean shop : shops) {
			print(shop.getSid());
		}
		api.setMethod(ShopApi.COUNT_METHOD);
		api.setGetParams();
		api.echoGet();
		api.get();
		System.out.println(api.getContent());
		*/
	}

}

